/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28318
 * Date: 2025-11-03
 * Time: 19:21
 */


class ListNode {
    int val;
    ListNode next;
    ListNode() {

    }
    ListNode(int val) {
        this.val = val;
    }
    ListNode(int val, ListNode next) {
        this.val = val; this.next = next;
    }

}

public class Main {

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        int carry = 0;
        int num = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val);
        ListNode ret = new ListNode(num % 10 + carry, (ListNode) null);
        carry = num / 10;
        ListNode p = ret;
        l1 = l1.next;
        l2 = l2.next;
        while (l1 != null || l2 != null) {
            num = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val);
            p.next = new ListNode(num % 10 + carry, (ListNode) null);
            carry = num / 10;
            p = p.next;
            l1 = l1 == null ? null : l1.next;
            l2 = l2 == null ? null : l2.next;
        }
        return ret;
    }

    public static void main0(String[] args) {

    }
}